<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('会员记录列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>姓名：</label>
                            <input type="text" name="userName"/>
                        </li>
                        <li>
                            <label>手机号：</label>
                            <input type="text" name="mobile"/>
                        </li>
                        <li>
                            <label>会员卡号：</label>
                            <input type="text" name="memberCardNumber"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="operator:order:recharge">
                <i class="fa fa-plus"></i> 充值
            </a>
            <a class="btn btn-primary " onclick="expensePage()" shiro:hasPermission="operator:order:expense">
                <i class="fa fa-minus"></i> 消费
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="operator:order:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">

    var orderTypeDATA = [[${@dict.getType('t_order_type')}]];
    var prefix = ctx + "operator/order";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/recharge",
            detailUrl: prefix + "/expense",
            exportUrl: prefix + "/export",
            headerStyle: headerStyle,
            modalName: "会员收支记录",
            sortName: "createTime",
            sortOrder: "desc",
            columns: [
                {
                    field: 'orderId',
                    title: '订单编号'
                },
                {
                    field: 'deptName',
                    title: '组织名称'
                },
                {
                    field: 'memberCardNumber',
                    title: '会员卡号'
                },
                {
                    field: 'mobile',
                    title: '手机号',
                    formatter: function (value, row, index) {
                        var reg = /^(\d{3})\d{4}(\d{4})$/;
                        return value.replace(reg, "$1****$2");
                    }
                },
                {
                    field: 'createTime',
                    title: '时间'
                },
                {
                    field: 'behalfType',
                    title: '类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(orderTypeDATA, value);
                    }
                },
                {
                    field: 'consumeAmount',
                    title: '金额'
                },
                {
                    field: 'balance',
                    title: '账户余额'
                },
                {
                    field: 'createUser',
                    title: '创建者'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="detailPage(\'' + row.id + '\')"><i class="fa fa-search"></i>明细</a> ');
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });
    function expensePage() {
        $.modal.open("会员消费",  prefix + "/expense/");
    }

    function headerStyle(column) {
        return {
            consumeAmount: {
                css: { color: 'red' }
            }
        } [column.field]
    }

    function detailPage(id) {
        var url = prefix + '/detail/' + id;
        $.modal.openTab("充值消费明细", url);
    }
</script>
</body>
</html>